var express = require('express');
var router = express.Router();
const { loginModel, orderModel } = require('../model/model')

router.post('/login', async (req, res) => {
    let { username, password } = req.body
    let result = await loginModel.findOne({ user: username, password })
    // console.log(result);

    if (result) {
        res.send({ code: 200, msg: '登录成功', data: result })
    }
})

//修改头像
router.post('/EditInfo', async (req, res) => {
    let { _id, image } = req.body
    let result = await loginModel.updateOne({ _id }, { image })
    if (result) {
        res.send({ code: 200, msg: '修改成功', data: result })
    }
})

//下单
router.post('/addOrder', async (req, res) => {
    let data={
        name:req.body.name,
        price:req.body.price,
        img:req.body.img,
        detail:req.body.detail,
        Lid:req.body._id,
        status:req.body.status
    }
    await orderModel.create(data)
    res.send({ code: 200, msg: '下单成功' })
})

//查询订单
router.get('/getOrder', async (req, res) => {
    let data = await orderModel.find()
    res.send({ code: 200, msg: '查询成功', data })
})

module.exports = router;
